package com.hollysys.hollimsa.biz.istio.gateway.domain;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Map;

/**
 * @author wangyuxi
 */
@ApiModel(value = "添加网关需要的参数",description = "添加网关需要的参数")
@Data
public class GatewayVO implements Serializable {

    private static final long serialVersionUID = -7849437140872908627L;
    /** 网关名称 */
    @ApiModelProperty(value = "网关名称符合正则表达式 [a-z0-9]([-a-z0-9]*[a-z0-9])?",required = true)
    @NotEmpty(message="网关名称不能为空")
    @Pattern(regexp = "[a-z0-9]([-a-z0-9]*[a-z0-9])?", message = "不符合 DNS1123_LABEL_REGEX")
    private String name;

    @ApiModelProperty(value = "服务器规格列表",required = true)
    @Valid
    private InnerServer[] servers;

    @ApiModelProperty(value = "一个或多个标签，指示应在其上应用此网关配置的一组特定的Pod,==出口==",required = true)
    private Map<String, String> selector;

    @Data
    public static class InnerServer implements Serializable {
        private static final long serialVersionUID = 4312655713744146274L;
        /** 域名信息 */
        @ApiModelProperty(value = "域名信息 参考istio官方地址 https://istio.io/latest/zh/docs/reference/config/networking/gateway/#Server#hosts描述 ",required = true)
        @NotNull(message="域名信息不能为空")
        @Size(min = 1,message = "至少一个host")
        private String[] hosts;
        @ApiModelProperty(value = "代理应在其上侦听传入连接的端口。",required = true)
        @Valid
        private InnerPort port;
    }

    @Data
    public static class InnerPort implements Serializable{

        private static final long serialVersionUID = -6084213113322647256L;
        @ApiModelProperty(value = "有效的非负整数端口号",required = true)
        private Integer number;

        @ApiModelProperty(value = "该协议在端口上公开。必须是HTTP | HTTPS | GRPC | HTTP2 | MONGO | TCP | TLS之一",required = true)
        private String protocol;

        @ApiModelProperty(value = "分配给端口的标签")
        private String name;
    }
}
